using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using SBPweb.Modules.Modularity;

namespace SBPweb.Presentation.Windows.Forms.Controls
{
		[ToolboxBitmap(typeof(System.Windows.Forms.MessageBox))]
		public partial class ProgressControl : SBPweb.Presentation.Windows.Forms.Controls.ModalDockingUserControl
		{
			private Color mColorFrom = Color.White;
			private Color mColorTo = Color.LightGreen;
			private LinearGradientBrush mBrush = null;
			private int mPosition = 0;
			private bool mGo = true;
			private Timer mTimer;

            /// <summary>
            /// ProgressControl
            /// </summary>
            /// <param name="parentModule">Parent module</param>
			public ProgressControl(ModuleBase parentModule)
				:base(parentModule)
			{
				InitializeComponent();
                BorderStyle = SBPweb.Modules.Smartparts.BorderStyle.FixedToolWindow;
                IsShowInWindowMenu = false;
                Dock = DockStyle.Fill;
                FloatingSize = this.Size;

				//this.BackgroundImage = global::SBPweb.Controls.Windows.Properties.Resources.Back_01_1x200;
				SetBrush();

				pBar.MarqueeAnimationSpeed = 1000;

				mTimer = new Timer();
				mTimer.Tick += new EventHandler(timer_Tick);
				mTimer.Interval = 100;
				mTimer.Enabled = true;
			}

            /// <summary>
            /// Color From
            /// </summary>
			[Category("Appearance")]
			public Color ColorFrom
			{
				get
				{
					return mColorFrom;
				}
				set
				{
					mColorFrom = value;
					SetBrush();
				}
			}

            /// <summary>
            /// Color To
            /// </summary>
			[Category("Appearance")]
			public Color ColorTo
			{
				get
				{
					return mColorTo;
				}
				set
				{
					mColorTo = value;
					SetBrush();
				}
			}

            /// <summary>
            /// Progress Caption
            /// </summary>
			[Category("Appearance")]
			public string ProgressCaption
			{
				get
				{
					return base.Caption;
				}
				set
				{
					base.Caption = value;
				}
			}

            /// <summary>
            /// Progress Text
            /// </summary>
			[Category("Appearance")]
			public string ProgressText
			{
				get
				{
					return lCaption.Text;
				}
				set
				{
					lCaption.Text = value;
				}
			}

			private void SetBrush()
			{
				Rectangle rect = new Rectangle(this.ClientRectangle.Left - this.ClientRectangle.Width, this.ClientRectangle.Left - this.ClientRectangle.Width, this.ClientRectangle.Width * 2, this.ClientRectangle.Width * 2);
				mBrush = new LinearGradientBrush(rect, mColorFrom, mColorTo, LinearGradientMode.ForwardDiagonal);
				pBar.ForeColor = mColorTo;
			}

			protected override void OnPaint(PaintEventArgs e)
			{
				base.OnPaint(e);
				if (this.BackgroundImage != null)
				{
					e.Graphics.DrawImage(this.BackgroundImage, this.ClientRectangle);
				}
			}

			protected override void OnPaintBackground(PaintEventArgs e)
			{
				base.OnPaintBackground(e);

				e.Graphics.FillRectangle(mBrush, this.ClientRectangle);
			}

			private void DoProgress()
			{
				mPosition++;

				if (mPosition > 360)
				{
					mPosition = 0;
					mGo = !mGo;
				}

				if (mGo)
				{
					mBrush.RotateTransform(3.0F);
				}
				else
				{
					mBrush.RotateTransform(-3.0F);
				}

				pBar.Value = mPosition;

				Invalidate();
			}

			protected override void OnVisibleChanged(EventArgs e)
			{
				base.OnVisibleChanged(e);
				mTimer.Enabled = this.Visible;
			}

			private void timer_Tick(object sender, EventArgs e)
			{
				DoProgress();
			}

	}
}
